import {WallEvent} from "./BeatMapParser"
import {BeatMapParserV3, NoteEventV3} from "./BeatMapParserV3"

class NoteEventV4 extends NoteEventV3 {
  RotationLane
}

class BeatMapParserV4 extends BeatMapParserV3 {

  initWallEvents(){
    for(let i= 0; i < this.data['obstacles'].length; i++){
      const rawData = this.data['obstacles'][i]
      const metaDataIndex = rawData?.i ?? 0;
      const metaData = this.data['obstaclesData'][metaDataIndex]

      const newEvent = new WallEvent()
      Object.assign(newEvent, {
        Index: i,
        Beat: rawData['b'],
        RotationLane: rawData?.r ?? 0,
        LineIndex: metaData?.x ?? 0,
        LineLayer: metaData?.y ?? 0,
        Height: metaData?.h ?? 0,
        Width: metaData?.w ?? 0,
        Duration:  metaData?.d ?? 0,        
      })
      this.wallEvents.push(newEvent)
    }
  }

  initNoteEvents(){
    for(let i= 0; i < this.data['colorNotes'].length; i++){
      const rawData = this.data['colorNotes'][i]
      const metaDataIndex = 'i' in rawData?rawData.i:0;
      const rawEventData = this.data['colorNotesData'][metaDataIndex];
      const newEvent = new NoteEventV4()
      Object.assign(newEvent, {
        Index: i,
        Beat: rawData.b,
        LineIndex: 'x' in rawEventData?rawEventData.x:0,
        LineLayer: 'y' in rawEventData?rawEventData.y:0,
        Type: 'c' in rawEventData?rawEventData.c:0,
        CutDirection: 'd' in rawEventData?rawEventData.d:0,
        AngleOffset: 'a' in rawEventData?rawEventData.a:0,
        RotationLane: rawData.r
      })
      this.noteEvents.push(newEvent)
    }
  }
}

export {BeatMapParserV4}